<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>父子组件嵌套</title>
    <!--引入Vue-->
    <script type="text/javascript" src="./js/vue.js"></script>
</head>

<body>
    <div id="root">
        <app></app>
    </div>
</body>

<script>
    //子组件
    const student = Vue.extend({
        template: `
        <div>
            <h2>学生姓名:{{studentName}}</h2>
            <h2>学生年龄:{{age}}</h2>
        </div>
        `,
        data() {
            return {
                studentName: "邓紫棋",
                age: 18
            }
        },
        methods: {
            showname() {
                alert(this.studentName)

            }
        }
    })

    //父组件
    const aihao = Vue.extend({
        template: `
        <div>
            <h2>爱好:{{stud}}</h2>
            <h2>哈哈哈:{{age}}</h2>
            
            <my-student></my-student>
        </div>
        `,
        data() {
            return {
                stud: "喜欢邓紫棋",
                age: 30
            }
        },
        //注册子组件
        components: {
            "my-student": student,
        }
    })

    //定义app组件（app组件是在vm之下，所有组件之上的的组件）

    const app = Vue.extend({
        template: `
        <div>
            <aihao></aihao>
        </div>
        `,
        data() {
            return {
                hello: "123",
                school: "456"
            }
        },
        //注册组件
        components: {
            aihao
        }

    })


    //所有组件都被vm来支配怎么用
    new Vue({
        el: "#root",
        data: {},

        //局部注册组件
        components: {
            app
        }
    })
</script>

</html>